package com.C3P0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class C3P0Demo1 {
    public static void main(String[] args) throws SQLException {
        //创建c3p0连接池对象
        DataSource dataSource=new ComboPooledDataSource();

        //获取数据库连接进行使用
        Connection con=dataSource.getConnection();


        String sql="SELECT * FROM student";
        PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs=pst.executeQuery();

        while (rs.next()){
            System.out.println(rs.getInt("id") + "\t" + rs.getString("name") + "\t" + rs.getInt("age") + "\t" + rs.getDate("birthday"));
        }
        con.close();
        pst.close();
        rs.close();
    }
}
